package com.example.mqttdemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class MqttController {

    @Autowired
    private MqttSender mqttSender;

    /**
     *   http://localhost:8080/send/topic1/message1
     *   http://localhost:8080/send/topic2/message2
     * @param topic
     * @param message
     * @return
     */
    @RequestMapping("/send/{topic}/{message}")
    public String send(@PathVariable String topic, @PathVariable String message) {
        // 发送消息到指定topic
        mqttSender.sendToMqtt(topic, message);
        return "send message : " + message;
    }
}
